package phoenix.web.test_suites.benaughty.critical;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import phoenix.core.base.TestSuiteBase;
import phoenix.core.config.extensions.ConfigExt;
import phoenix.core.data_models.TestUserDataModel;
import phoenix.core.data_models.UserProfileDataModel;
import phoenix.web.test_objects.BackendTests;
import phoenix.web.test_objects.FunnelTests;
import phoenix.web.test_objects.LoginTests;
import phoenix.web.test_objects.MyAccountTests;
import phoenix.web.test_objects.PaymentTests;
import phoenix.web.test_objects.RegistrationTests;
import phoenix.web.test_objects.UserPageTests;
import phoenix.web.test_objects.WelcomePopupTests;
import phoenix.web.test_objects.crm.MailTests;

/**
 * Test suite - Login and Logout tests
 */
public class CrmTS extends TestSuiteBase
{
	// Tests
	private final RegistrationTests registrationTests = new RegistrationTests(phoenix);
	private final BackendTests backendTests = new BackendTests(phoenix);
	private final FunnelTests funnelTests = new FunnelTests(phoenix);
	private final MailTests mailTests = new MailTests(phoenix);
	private final UserPageTests userPageTests = new UserPageTests(phoenix);
	private final MyAccountTests myAccountTests = new MyAccountTests(phoenix);
	private final PaymentTests paymentTests = new PaymentTests(phoenix);
	private final WelcomePopupTests welcomePopupTests = new WelcomePopupTests(phoenix);
	private final LoginTests loginTests = new LoginTests(phoenix);

	@DataProvider
	public Object[][] registrationDataMale()
	{
		return registrationTests.dataProviders.registrationDataMale();
	}

	@DataProvider
	public Object[][] registrationDataFemale()
	{
		return registrationTests.dataProviders.registrationDataFemale();
	}

	@DataProvider
	public Object[][] funnelData()
	{
		return funnelTests.dataProviders.funnelData();
	}

	@DataProvider
	public Object[][] messageLetterTestData()
	{
		return mailTests.dataProviders.messageLetterData();
	}

	@DataProvider
	public Object[][] resendLetterTestData()
	{
		return mailTests.dataProviders.resendLetterData();
	}

	@DataProvider
	public Object[][] changeLetterTestData()
	{
		return mailTests.dataProviders.changeLetterData();
	}

	@DataProvider
	public Object[][] paymentDataSuccess()
	{
		return paymentTests.dataProviders.paymentDataSuccess();
	}

	@Test(dataProvider = "registrationDataMale", priority = 1, groups = { "male" }, enabled = true)
	public void registrationMaleTest(String p_userGender, String p_userEmail, String p_userPassword, String
			p_userBirthDay,
			String p_userBirthMonth, String p_userBirthYear)
	{
		registrationTests.registrationTest(p_userGender, p_userEmail, p_userPassword, p_userBirthDay,
				p_userBirthMonth, p_userBirthYear);
	}

	@Test(dependsOnMethods = "registrationMaleTest", priority = 2, groups = { "male" }, enabled = true)
	public void getUserDataTest()
	{
		backendTests.getUserDataTest(testUser().getEmail());
	}

	@Test(dependsOnMethods = "getUserDataTest", enabled = true, priority = 3)
	public void welcomeLetterTest()
	{
		wd().wait(ConfigExt.MAIL_DELAY);
		mailTests.welcomeLetterTest(testUser().getEmail());
	}

	@Test(dependsOnMethods = "welcomeLetterTest", groups = { "male" }, enabled = true, priority = 4)
	public void confirmationTest()
	{
		funnelTests.confirmationTest();
	}

	@Test(dependsOnMethods = "welcomeLetterTest", groups = { "male" }, dataProvider = "funnelData", enabled = true,
			priority = 5)
	public void funnelMaleTest(String p_screenName, UserProfileDataModel.LookingFor p_lookingForParams, UserProfileDataModel.AboutMe p_aboutMeParams)
	{
		funnelTests.funnelTest(p_screenName, p_lookingForParams, p_aboutMeParams);
	}

	@Test(dependsOnMethods = "welcomeLetterTest", dataProvider = "messageLetterTestData", priority = 6, enabled = false)
	public void messageLetterTest(TestUserDataModel p_userSender, TestUserDataModel p_userRecipient)
	{
		userPageTests.testForActivityMessages(p_userSender, p_userRecipient);
		wd().wait(ConfigExt.MAIL_DELAY);
		mailTests.messageLetterTest(testUser().getEmail(), testUser().getScreenname());
	}

	@Test(dependsOnMethods = "messageLetterTest", enabled = false, priority = 7)
	public void winkLetterTest(String[] p_title, String p_email)
	{
		mailTests.winkLetterTest(testUser().getEmail(), testUser().getScreenname());
	}

	@Test(dependsOnMethods = "messageLetterTest", enabled = false, priority = 8)
	public void browseLetterTest()
	{
		mailTests.browseLetterTest(testUser().getEmail(), testUser().getScreenname());
	}

	@Test(dependsOnMethods = "confirmationTest", enabled = true, priority = 9)
	public void forgotLetterTest()
	{
		loginTests.forgotPasswordTest(testUser().getEmail());
		wd().wait(ConfigExt.MAIL_DELAY);
		mailTests.forgotLetterTest(testUser().getEmail());
	}

	// https://redmine.platformphoenix.com/issues/144055
	@Test(dependsOnMethods = { "confirmationTest" }, priority = 10, enabled = false)
	public void passwordReminderRemoveTest()
	{
		myAccountTests.passwordReminderRemoveAccount(testUser().getEmail());
		wd().wait(ConfigExt.MAIL_DELAY);
		mailTests.forgotLetterTest(testUser().getEmail());
	}

	// https://redmine.platformphoenix.com/issues/144055
	@Test(dependsOnMethods = { "confirmationTest" }, groups = { "male" }, priority = 11, dataProvider = "paymentDataSuccess",
			enabled = false)
	public void paymentPackageTest(UserProfileDataModel.PaymentDetails p_paymentDataParams, Boolean p_expectedResult)
	{
		paymentTests.paymentPackageTest(p_paymentDataParams, p_expectedResult);
	}

	// https://redmine.platformphoenix.com/issues/144055
	@Test(dependsOnMethods = { "paymentPackageTest" }, priority = 12, enabled = false)
	public void passwordReminderBillingTest(String[] p_title, String p_email)
	{
		myAccountTests.passwordReminderBillingHistory(p_email);
		wd().wait(ConfigExt.MAIL_DELAY);
		mailTests.forgotLetterTest(testUser().getEmail());
	}

	// #133196
	@Test(dependsOnMethods = "confirmationTest", enabled = false, priority = 13)
	public void matchLetterTest()
	{
		mailTests.matchLetterTest(testUser().getEmail(), testUser().getScreenname());
	}

	@Test(dependsOnMethods = { "confirmationTest" }, dataProvider = "changeLetterTestData", enabled = true, priority = 14, alwaysRun = true)
	public void changeEmailLetterTest(TestUserDataModel p_user, String p_email)
	{
		registrationTests.registrationTest(p_user.getGender(), p_user.getEmail(), p_user.getPassword(), p_user.getBirthDay(), p_user.getBirthMonth(),
				p_user.getBirthYear());
		backendTests.getUserDataTest(testUser().getEmail());
		welcomePopupTests.changeEmailTest(p_email);
		wd().wait(ConfigExt.MAIL_DELAY);
		mailTests.welcomeLetterTest(p_email);
		testUser().setEmail(p_email);
	}

	@Test(dependsOnMethods = { "confirmationTest" }, dataProvider = "resendLetterTestData", enabled = true, priority = 15, alwaysRun = true)
	public void resendLetterTest(TestUserDataModel p_user)
	{
		registrationTests.registrationTest(p_user.getGender(), p_user.getEmail(), p_user.getPassword(), p_user.getBirthDay(), p_user.getBirthMonth(),
				p_user.getBirthYear());
		backendTests.getUserDataTest(testUser().getEmail());
		welcomePopupTests.resendEmailTest();
		// We do assume, first mail is welcome
		wd().wait(ConfigExt.MAIL_DELAY);
		mailTests.welcomeLetterTest(testUser().getEmail()); // Welcome letter

		// Now we must find second message
		wd().wait(ConfigExt.MAIL_DELAY);
		mailTests.welcomeLetterTest(testUser().getEmail()); // Resend letter
	}
}
